from typing import Sequence

from fastapi import APIRouter, Security
from fastapi.responses import StreamingResponse

from app.deps.authorize_deps import validate_permissions
from app.deps.base_deps import DynamicQueryDep, IdsQueryDep
from app.deps.controller_deps import LoginLogControllerDep as ControllerDep
from app.models.base import IdType
from app.schemas.base_schema import AuthScopePrefixConst
from app.schemas.login_log_schema import LoginLogOut as OutModel, LoginLogExport as ExportModel
from app.schemas.result_schema import ResultModel, PageModel

login_log_router = APIRouter()

SCOPE_PREFIX=AuthScopePrefixConst.LOGIN_LOG_SCOPE_PREFIX.value

@login_log_router.get("/get_all", summary="获取所有",dependencies=[Security(validate_permissions, scopes=[f"{SCOPE_PREFIX}view"])])
async def get_all(query_in: DynamicQueryDep, controller: ControllerDep) -> ResultModel[Sequence[OutModel]]:
    return await controller.get_all( query_in=query_in)

@login_log_router.get("/get_page/{current_page}/{page_size}", summary="分页获取",dependencies=[Security(validate_permissions, scopes=[f"{SCOPE_PREFIX}view"])])
async def get_page(current_page: int, page_size: int, query_in: DynamicQueryDep, controller: ControllerDep) -> ResultModel[PageModel[OutModel]]:
    return await controller.get_page(current_page=current_page, page_size=page_size, query_in=query_in,)

@login_log_router.get("/get_by_id/{id}", summary="根据ID获取",dependencies=[Security(validate_permissions, scopes=[f"{SCOPE_PREFIX}view"])])
async def get_by_id(id: IdType,controller: ControllerDep) -> ResultModel[OutModel]:
    return await controller.get_by_id(id=id)

@login_log_router.get("/get_by_ids", summary="根据ID列表获取",dependencies=[Security(validate_permissions, scopes=[f"{SCOPE_PREFIX}view"])])
async def get_by_ids(ids:IdsQueryDep,controller: ControllerDep) -> ResultModel[Sequence[OutModel]]:
    return await controller.get_by_ids(ids=ids)

@login_log_router.post("/batch_export", summary="批量导出",dependencies=[Security(validate_permissions, scopes=[f"{SCOPE_PREFIX}export"])])
async def batch_export(ids:Sequence[IdType],controller: ControllerDep) -> StreamingResponse:
    return await controller.batch_export(ExportModel,ids=ids,export_name="登录日志数据")
